#include "SoundFile.h"


SoundFile::SoundFile()
	: m_pSndFile(NULL)
{
}


SoundFile::~SoundFile()
{

}

int SoundFile::Open(const char* path)
{
	m_pSndFile = sf_open(path, SFM_READ, &m_SndInfo);

	if (m_pSndFile == NULL) {
		return -1;
	}
	return 0;
}

int SoundFile::Close()
{
	if (m_pSndFile == NULL) {
		return -1;
	}
	return sf_close(m_pSndFile);
}

long long SoundFile::Read(short* buffer, long long size)
{
	if (m_pSndFile == NULL) {
		return 0;
	}
	long long result = sf_readf_short(m_pSndFile, buffer, size);
	return result;
}

int SoundFile::GetSampleRate()
{
	return m_SndInfo.samplerate;
}

int SoundFile::GetChannels()
{
	return m_SndInfo.channels;
}

int SoundFile::GetSections()
{
	return m_SndInfo.sections;
}

long long SoundFile::GetFrames()
{
	return m_SndInfo.frames;
}

SoundFile::Format SoundFile::GetFormat()
{
	switch (m_SndInfo.format)
	{
	case SF_FORMAT_WAV:
		return SoundFile::WAVE;
	case SF_FORMAT_OGG:
		return SoundFile::OGG;
	default:
		return SoundFile::OTHER;
	}
}